home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-10-01 | 5.3 KB | 244 lines | [TEXT/MPCC] |
- /********************************************
- **** Animation Class Library V1.0 © 1994 Yves Schmid & Alia Development
- ****
- **** SimpleDemo.cp
- ****
- **** Created: 27 May 1994
- **** Modified: 09 June 1994
- **** Version: 0
- **** Compatible: C++, Mac System 7
- ****
- **** Description: A simple demo of ACL.
- ****
- *******************/
-
-
- #include "AnimBase.h"
-
- //*************************************
-
- const long PICT_BACKGROUND = 128;
-
- const long PICT_ANIM1 = 129;
- const long PICT_ANIM2 = 135;
-
-
- //*************************************
- // Definition of the two animation types:
-
- AnimFrameDef anim1[] = {{PICT_ANIM1 ,NULL,1,0,0,afcmd_frame},
- {PICT_ANIM1+1,NULL,1,0,0,afcmd_frame},
- {PICT_ANIM1+2,NULL,1,0,0,afcmd_frame},
- {PICT_ANIM1+3,NULL,1,0,0,afcmd_frame},
- {PICT_ANIM1+4,NULL,1,0,0,afcmd_frame},
- {PICT_ANIM1+5,NULL,1,0,0,afcmd_endanim}};
-
- AnimFrameDef anim2[] = {{PICT_ANIM2 ,NULL,1,0,0,afcmd_frame},
- {PICT_ANIM2+1,NULL,1,0,0,afcmd_frame},
- {PICT_ANIM2+2,NULL,1,0,0,afcmd_frame},
- {PICT_ANIM2+3,NULL,1,0,0,afcmd_frame},
- {PICT_ANIM2+4,NULL,1,0,0,afcmd_frame},
- {PICT_ANIM2+5,NULL,1,0,0,afcmd_endanim}};
-
-
- //*************************************
-
- AnimBase *animbase; // The central animation control
- AnimGfx *background; // Pointer on background
-
- AnimControl controls[4]; // Four animation controls
- AnimControl gobackcontrols[4]; // Controls to place the animation at the left of the display
- // when the animation is out of screen.
-
- Anim *anims[4]; // Pointer on the four animations
-
- //*************************************
-
- Boolean testanimout(AnimCObject *a, AnimControl *c) // Used to test if the anim is out of screen.
- {
- if (a->getx()>=background->getwidth()) return TRUE;
-
- return FALSE;
- }
-
- //*************************************
-
- void InitToolbox()
- {
- InitGraf((Ptr) &qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- FlushEvents(everyEvent,0);
- TEInit();
- InitDialogs(0L);
- InitCursor();
- }
-
- //*************************************
-
- void InitAnim()
- {
- int i;
- short w;
-
- // Builds background
- background = new AnimGfx;
- background->createbypict(PICT_BACKGROUND); // Gets background in the pict resource
-
- // Builds AnimBase
- animbase = new AnimBase;
-
- // Installs background
- animbase->installbackground(background);
-
- // Creates an offscreen buffer to stop flickering, same size of the background
- animbase->buildbufferback();
-
- // Creates animations
- anims[0] = animbase->createanim(anim1);
- anims[1] = animbase->createanim(anim1);
- anims[2] = animbase->createanim(anim2);
- anims[3] = animbase->createanim(anim2);
-
- // Ping-pong animation
- anims[0]->setanimflags(ANF_PINGPONG);
- anims[1]->setanimflags(ANF_PINGPONG);
- anims[2]->setanimflags(ANF_PINGPONG);
- anims[3]->setanimflags(ANF_PINGPONG);
-
- // We don't want to see synchronous animations
- anims[0]->setcurrentframe(0);
- anims[1]->setcurrentframe(2);
- anims[2]->setcurrentframe(4);
- anims[3]->setcurrentframe(3);
-
- // Installs controls
-
- for(i=0;i<4;i++)
- {
- anims[i]->findmaxsize(&w,NULL);
- anims[i]->place(-w,i*20); // Places animation
-
- controls[i].cmd = acmd_move;
- controls[i].x = 8-(i*2); // A different speed for each animation
- controls[i].y = 0;
- controls[i].next = &gobackcontrols[i]; // Control to check if the animation is out of
- // the screen
-
- gobackcontrols[i].cmd = acmd_place;
- gobackcontrols[i].x = -w;
- gobackcontrols[i].y = i*20;
- gobackcontrols[i].testproc = &testanimout;
- gobackcontrols[i].next = &controls[i]; // Do a loop
-
- anims[i]->runcontrol(&controls[i]);
- }
- }
-
- //*************************************
-
- void Cleanup()
- {
- delete animbase;
- delete background;
- }
-
- //*************************************
-
- void waitwindow(Boolean openw)
- {
- static WindowPtr ww;
- Rect windowRect;
-
- if (openw)
- {
-
- SetRect(&windowRect,100,100,375,118);
-
- ww = NewCWindow(NULL,&windowRect,NULL,TRUE,
- dBoxProc,(WindowPtr)-1,FALSE,0);
-
- SetPort(ww);
- MoveTo(40,12);
- TextFont(systemFont);
- DrawString("\pPlease wait, initializing...");
- }
- else
- {
- DisposeWindow(ww);
- }
- }
-
- //*************************************
-
-
- main()
- {
- WindowPtr aWindow;
- Rect windowRect;
- Boolean done = FALSE;
- EventRecord theEvent;
- WindowPtr whichWindow;
- short part;
-
- InitToolbox();
-
- waitwindow(TRUE);
- InitAnim();
-
- SetRect(&windowRect,100,100,200,200);
- aWindow = NewCWindow(NULL,&windowRect,"\pSimple Demo of ACL",FALSE,
- noGrowDocProc,(WindowPtr)-1,TRUE,0);
-
- SetPort(aWindow);
- SizeWindow(aWindow,background->getwidth(),background->getheight(),TRUE);
-
-
- waitwindow(FALSE);
- ShowWindow(aWindow);
-
- while(!done)
- {
- animbase->update();
-
- if (WaitNextEvent(everyEvent,&theEvent,0,NULL))
- {
- switch(theEvent.what)
- {
- case updateEvt:
- whichWindow = (WindowPtr)theEvent.message;
- if (whichWindow==aWindow)
- {
- BeginUpdate(whichWindow);
- animbase->updatewindow();
- EndUpdate(whichWindow);
- }
- break;
-
- case mouseDown:
- part = FindWindow(theEvent.where,&whichWindow);
- if (whichWindow==aWindow)
- {
- switch(part)
- {
- case inGoAway:
- done = TrackGoAway(whichWindow,theEvent.where);
- break;
-
- case inDrag:
- DragWindow(whichWindow,theEvent.where,&qd.screenBits.bounds);
- break;
- }
- }
- break;
- }
- }
-
- }
-
- DisposeWindow(aWindow);
- Cleanup();
- return 0;
- }
-